package com.google.gwt.livinglife.client.widgets;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.Widget;

public class SortedWidgetList extends Composite implements ClickHandler{
	private String header;
	private Widget[] widgets;
	private Label topLabel = new Label();
	private DockPanel mainPanel = new DockPanel();
	private MenuBar menuBar = new MenuBar();
	private MenuBar sortBy = new MenuBar();
	private MenuBar timeRestriction = new MenuBar();

	public SortedWidgetList() {
		mainPanel.add(topLabel, DockPanel.NORTH);
		mainPanel.add(menuBar, DockPanel.NORTH);
		mainPanel.setSpacing(5);
		mainPanel.setWidth("350px");
		menuBar.setWidth("350px");
		menuBar.setAutoOpen(true);
		menuBar.setAnimationEnabled(true);
		menuBar.addItem("Time", timeRestriction);
		menuBar.addItem("Popularity", sortBy);
		
		mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		initWidget(mainPanel);
		Command menuCommand = new Command() {
			
			public void execute() {
				Window.alert("Hello");
			};
		};
		
	}
	public void setWidth(String width) {
		mainPanel.setWidth(width);
		menuBar.setWidth(width);
	}
	
	public void onModuleLoad() {
	}

	
	public String getHeader() {
		return header;
	}


	public void setHeader(String header) {
		this.header = header;
		topLabel.setText(header);
		topLabel.setTitle(header);
	}


	public Widget[] getWidgets() {
		return widgets;
	}


	public void setWidgets(Widget[] stories) {
		this.widgets = stories;
		mainPanel.clear();
		mainPanel.add(topLabel, DockPanel.NORTH);
		mainPanel.add(menuBar, DockPanel.NORTH);
		for( int i = 0; i < stories.length; ++i) {
			mainPanel.add(stories[i], DockPanel.NORTH);
		}
	}

	public DockPanel getMainPanel() {
		return mainPanel;
	}


	public void setMainPanel(DockPanel mainPanel) {
		this.mainPanel = mainPanel;
	}


	public MenuBar getMenuBar() {
		return menuBar;
	}


	public void setMenuBar(MenuBar menuBar) {
		this.menuBar = menuBar;
	}
	public void onClick(ClickEvent event) {
		// TODO Auto-generated method stub
		
	}

}
